home *** CD-ROM | disk | FTP | other *** search
- Path: news1.intercall.com!usenet
- From: engevar@intercall.com (Steven Ovits)
- Newsgroups: comp.lang.c
- Subject: Re: I need help.
- Date: Fri, 29 Mar 1996 17:51:23 GMT
- Organization: Intercall Inc.
- Message-ID: <4jguak$n6e@news1.intercall.com>
- References: <4j9hr7$skj@cronkite.seas.gwu.edu> <26MAR199615081545@erich.triumf.ca> <danpop.828046690@rscernix>
- NNTP-Posting-Host: ts2-98.intercall.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- danpop@mail.cern.ch (Dan Pop) wrote:
-
- >In <26MAR199615081545@erich.triumf.ca> bennett@erich.triumf.ca (P.Bennett) writes:
-
- >>In article <4j9hr7$skj@cronkite.seas.gwu.edu>, celtik@gwis2.circ.gwu.edu (Tolga Celtikci) writes...
- >>>Can anyone help me with the syntax of EOF. Is it '\o' or something else?
-
- >The "syntax" of EOF is EOF. It works fine after including <stdio.h>.
-
- Agreed.
-
- >On _some_ platforms it can be even written as a character constant: '\xff'
- >or '\377', but:
-
- >1. It is a very "efficient" way to obfuscate your code. Other people
- > will have a very hard time figuring out what you meant.
-
- >2. It will work only on platforms which use two's complement integers,
- > define EOF as -1 and treat char as an 8-bit signed type. OTOH, EOF
- > works everywhere.
-
- >>EOF is _not_ a char in the file. It is a value returned by getchar(), fgetc()
- >>and some other functions to indicate that they have attempted to read past
- >>end-of-file. It is a value that cannot be represented in a char, so getchar()
- > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- >Don't be so sure. Implementations with sizeof(char) == sizeof(int) are
- >legal and even exist. They're a royal pain in the ass when it comes to
- >testing for EOF, because EOF is also a valid character value, so after
- >reading an EOF you have to call ferror and feof to disambiguate between
- >a genuine char value and an end-of-file condition.
-
- This is correct, but the following will make it more definitive.
- I quote from the standard section of "The Standard C Library"
- by P. J. Plauger:
-
- "EOF which expands to an integral constant expression that is
- returned by several functions to indicate 'end-of-file,' that is,
- no more input from a stream."
-
- Notice it says nothing about whether the constant is valid in a file,
- so it can be.
-
- "The feof function test the 'end-of-file' indicator for the stream
- pointed to by stream."
-
- Therefore, it is a good idea to always use feof and only feof to
- test for the end of input.
-
- The only caveat I'm aware of is that a system is free to pad
- binary files with an 0 bytes, so the end-of-file may or may not be
- reported--I don't know the standard or practice on this.
-
- My only question is why would you have to test ferror? Is this
- related to the problem some systems have of distinguishing the
- end-of-file?
-
-
-